
//981.基于时间的键值存储
class TimeMap {

    unordered_map<string,vector<pair<int,string>>> nums;  //first存储key，vector<pair>存储时间戳和value
    int time=0;
public:
    TimeMap() {}
    
    void set(string key, string value, int timestamp) {
        nums[key].push_back({timestamp,value});
    }
    
    string get(string key, int timestamp) {
        //把键值位key的数组拿出来
        auto& tmp=nums[key];

        //使用upper_bound找大于timestamp的位置
        int pos=ranges::upper_bound(tmp,timestamp,{},[](auto e){return e.first;})-tmp.begin()-1;
        if(pos<0) return "";
        return tmp[pos].second;
    }
};

/**
 * Your TimeMap object will be instantiated and called as such:
 * TimeMap* obj = new TimeMap();
 * obj->set(key,value,timestamp);
 * string param_2 = obj->get(key,timestamp);
 */